package com.gy.api.mobile.msg.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.github.pagehelper.PageInfo;
import com.gy.api.base.ApiIndex;
import com.gy.api.base.R;
import com.gy.api.base.RestPage;
import com.gy.api.mobile.msg.domain.vo.MessageListHandleDto;
import com.gy.api.mobile.msg.domain.vo.MessageResDto;
import com.gy.api.mobile.msg.service.IUserMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/message")
@Api( tags = ApiIndex.UserMessageController)
@Slf4j
public class UserMessageController{

    @Resource
    private IUserMessageService userMessageService;

    @ApiOperation("查询当前登录用户未办理的消息列表")
    @GetMapping("/list")
    public R<RestPage<MessageResDto>> list() {
        List<MessageResDto> list = userMessageService.getList(StpUtil.getLoginIdAsString());
        RestPage restPage = new RestPage( new PageInfo(list),list);
        return new R(restPage);
    }

    @ApiOperation("将消息状态从未读变为已读消息")
    @PutMapping("/handle")
    public R handle(@RequestBody MessageListHandleDto messageListHandleDto) {
        userMessageService.handle(messageListHandleDto.getMessageIdList());
        return new R();
    }
    @ApiOperation("查看消息详情")
    @GetMapping("/detail")
    public R<MessageResDto> detail(String messageId){
        return new R(userMessageService.detail(messageId));
    }

    @ApiOperation("删除消息")
    @DeleteMapping("/delete")
    public R delete(@RequestBody MessageListHandleDto messageListHandleDto) {
         userMessageService.delete(messageListHandleDto.getMessageIdList());
        return new R();
    }
}
